<!doctype html>   <!--视频课程下的课程分类-->
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>Bootstrap 101 Template</title>
    <link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="assets/css/common.css">
</head>
<body>
<!-- 顶部-->
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="index.html">长乐未央</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li class="active"><a href="#">视频课程 <span class="sr-only">(current)</span></a></li>
            </ul>
            <form class="navbar-form navbar-left">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="请填写搜索的课程">
                </div>
                <button type="submit" class="btn btn-default">搜索</button>
            </form>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>

<div class="container">
    <div class="page-header">
        <h1>课程分类<small>Categories</small></h1>
    </div>
    <ul class="list-group">
        <!-- <li class="list-group-item">
             <a href="list.html">Web前端</a>
         </li>-->
    </ul>
</div>

<script src="vendor/jquery-3.6.0.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<script>
    $(function () {
        $.get("https://clwy.cn/video/api/v2/categories.json", function (data) {  //读取接口全部数据，存入data里面
            console.log(data)
            var categories = data.categories;                             /*获取接口数据中匹配的数组数据*/
            var list_item = ''                                           //定义一个内容为空的变量
            $.each(categories, function (index, value) {               //遍历categories指定数组循环，将数组中的每一项分别读取到，拼接成html
                list_item += '<li class="list-group-item">\n' +
                    '            <a href="javascript:;" data-id="' + value.id + '">' + value.name + '</a>\n' +   //获取课程分类id值
                    '        </li>'
            })

            $('.list-group').html(list_item)                          //添加到html页面中

            /*点击事件*/
            $(".list-group").on("click", "a", function () {
                var categoryId = $(this).data("id");
              /*  console.log(categoryId)*/
                localStorage.categoryId = categoryId;        /*把点击后获取的值存储在‘本地存储空间’里面*/
                location.href="list.html"


            })


        })

    })
</script>

</body>
</html>
